<!DOCTYPE html>
<!--suppress ALL-->
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous" />
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
</head>
<body>
<div class="container-fluid" id="app">
    <div class="row">
        <div class="col-md-12 text-center" style="background-color: red; color: white" >
            <h3>蜗牛书店</h3>
        </div>
    </div>

    <div class="row">
        <div class="col-md-6">
            <ol class="breadcrumb">
                <li v-for="bt in typelist"><a href="javascript:void(0)" :href="'/book/showBookView/?typeid='+bt.id" v-text="bt.name"></a></li>
            </ol>
        </div>

        <div class="col-md-3">
            <form class="form-inline">
                <div class="form-group">
                    <label for="search" class="sr-only">请输入关键词</label>
                    <input type="text" class="form-control" v-model="searchName" id="search" placeholder="请输入关键词">
                </div>
                <button type="button" @click.prevent="searchBook" class="btn btn-default">搜索</button>
            </form>
        </div>

        <div class="col-md-3">
            <button type="button" class="btn btn-default btn-sm">个人中心</button>
            <button type="button" class="btn btn-default btn-sm">我的购物车</button>
            <button type="button" class="btn btn-default btn-sm">我的订单</button>
        </div>
    </div>

    <div class="row">
        <div class="row">
            <div class="col-sm-6 col-md-4" v-for="b in bookList">
                <div class="thumbnail">
                    <a :href="'/book/singleBook?bid='+b.id"><img :src="b.imgsrc" alt="图片"></a>
                    <div class="caption text-center">
                        <p>书名:<span v-text="b.name"></span></p>
                        <p>价格:<span  v-text="b.price"></span></p>
                        <!--<span v-text="index"></span>-->
                        <p>
                            <a class="btn btn-primary" :href="'/book/singleBook?bid='+b.id">详情</a>  &nbsp;&nbsp;&nbsp;&nbsp;
                            <a class="btn btn-primary" href="javascript:void(0)" @click="addToCart(b.id)">加入购物车</a>
                        </p>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script th:inline="javascript">
    let vueApp = new Vue({
        el:"#app",
        data:{
            typelist:[],
            searchName:[[${searchName}]],
            bookList:[]
        },
        methods:{
            initBookType(){
                let _this = this ;
                let url = "/home/typeList" ;
                $.get(url,function (data){
                    console.log(data);
                    _this.typelist = data ;
                },"json")
            },
            searchBook(){
                let _this = this ;
                let url = "/book/searchBook";
                $.post(url,{"keyWords":_this.searchName},function (data){
                    _this.bookList = data ;
                },"json")
            }
        },
        created(){
            this.initBookType();
            this.searchBook();
        }
    })
</script>
</body>
</html>